package com.label.Model.Do;

import com.alibaba.fastjson.annotation.JSONField;
import com.alibaba.fastjson.serializer.ToStringSerializer;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.label.Utils.Common.InfoUtil;
import lombok.Data;

import java.io.Serializable;
import java.util.List;

/**
 * User
 * @author dolyw.com
 * @date 2018/8/31 14:43
 */

@TableName(value = "sysuser")
@Data
public class User implements Serializable {

    @TableId(type = IdType.ASSIGN_ID)
    @JSONField(serializeUsing= ToStringSerializer.class)
    private Long id;


    private String account;

    private String password;

    @TableField(value = "username")
    private String userName;

    @TableField(value = "unit_id")
    private String unitId;

    @TableField(value = "school_id")
    private String schoolId;

    @TableField(value = "major_id")
    private String majorId;

    @TableField(value = "class_id")
    private String classId;

    @TableField(value = "op_level")
    private String opLevel;

    private String phone;

    private String email;

    @TableField(value = "department_id")
    private String department;

    @TableField(value = "parent_email")
    private String parentEmail;

    @TableField(value = "pic_path")
    private String picPath;

    @TableField(exist = false)
    private List<Role> roles;

    public String getUnitName() {
        if(unitId!=null){
            return InfoUtil.getUnitName(unitId);
        }
        return null;
    }

    public String getSchoolName() {
        if(schoolId!=null){
            return InfoUtil.getSchoolName(schoolId);
        }
        return null;
    }

    public String getDepartmentName() {
        if(department!=null){
            return InfoUtil.getDepartmentName(department);
        }
        return null;
    }
}
